package progetto;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import peersim.core.CommonState;
import peersim.util.FileNameGenerator;

public class FileNameGeneratorExt extends FileNameGenerator {


	// ==================== initialization ==============================
	// ==================================================================
	
	/**
	* @param prefix all returned names will be prefixed by this
	* @param ext will be appended to all returned names
	*/
	public FileNameGeneratorExt(String prefix, String ext) {
		super(prefix, ext);
		// TODO Auto-generated constructor stub
	}
	

	// ===================== methods ====================================
	// ==================================================================


	/**
	* Generates a name based on a counter.
	* The format of the name returned is {@link #prefix} followed by
	* an 8 digit zero padded number, followed by {@link #ext}.
	* The first number used is zero.
	* @return the next filename after increasing the counter
	*/
	public String nextTimerName() {
		long time = System.currentTimeMillis();
		
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		//(new PrintStream(baos)).printf("%08d", time);
		(new PrintStream(baos)).print(time);
		return prefix+baos.toString()+ext;
	}
	
	public String nextSeedName() {
		long seed = CommonState.r.getLastSeed();
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		//(new PrintStream(baos)).printf("%08d", time);
		(new PrintStream(baos)).print(seed);
		return prefix+baos.toString()+ext;
	}
	
	
	

}
